<?php header('Content-Type: text/xml'); ?>
<?php
echo '<?xml version="1.0" encoding="utf-8"?>';

function clean($str) {
    $str = @trim($str);
    if (get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
}
?>


<rss version="2.0">
    <channel>
        <title>Simple Blog - Newsfeed</title>
        <link>http://localhost/simpleblog</link>
        <description> RSS From Simple Blog</description>
        <language>vn</language>

        <?php
        require_once 'DatabaseHelper.php';
        DatabaseHelper::getInstance()->connect();
        $query = "SELECT * FROM post";

        $result = DatabaseHelper::getInstance()->query($query);
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            // Display each row as an RSS item
            echo '<item>';
            echo '  <title>' . $row['title'] . '</title>';
            echo '  <link>http://localhost/simpleblog/index.php?id=' . $row['id'] . '</link>';

            $dateString = date('H:i:s d-m-Y', $row['timestamp']);
            echo '  <pubDate>' . $dateString . '</pubDate>';

//            $descript = substr($row['entry'], 0, 150);
//            $des = clean($descript);
//            echo '  <description>' . $des . '</description>';
            echo '</item>';
        }
        ?>

    </channel>
</rss>
